package com.dong.cutesms.components;

import java.util.List;

import com.dong.cutesms.R;
import com.dong.cutesms.constant.AppParameters;
import com.dong.cutesms.constant.SmsTable;
import com.dong.cutesms.models.SmsModel;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatRegionAdapter2 extends BaseAdapter {

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}

	private Activity context;

	private List plotsImages;
	private static ViewHolder holder;
	private LayoutInflater l_Inflater;

	public ChatRegionAdapter2(Activity context, List plotsImages,
			List<SmsModel> _smsList) {
		this.context = context;
		this.plotsImages = plotsImages;
		l_Inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// System.out.println("count="+
		// String.valueOf(AppParameters.smsList.size()));
		if (AppParameters.smsList == null) {
			return 0;
		}
		return AppParameters.smsList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return AppParameters.smsList.get(position).id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = l_Inflater.inflate(
					R.layout.item_activity_chat_region_2, null);
			holder = new ViewHolder();
			holder.imageView = (ImageView) convertView
					.findViewById(R.id.iv_chat_avatar);
			holder.tv = (TextView) convertView
					.findViewById(R.id.tv_chat_content);
			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();
		}

		SmsModel sms = AppParameters.smsList.get(position);

		System.out.print("position:");
		System.out.println(position);

		int smsType = sms.type;
		if (smsType == SmsTable.MESSAGE_TYPE_INBOX) {
			holder.imageView.setImageResource(AppParameters.people.avatarID);
			// holder.tv.setBackgroundResource(R.drawable.chat_bubble2);
		} else {
			holder.imageView.setImageDrawable((Drawable) plotsImages.get(1));
			// holder.tv.setBackgroundResource(R.drawable.chat_bubble);
		}
		String message = sms.body;
		holder.tv.setText(message);

		return convertView;
	}

	private static class ViewHolder {
		ImageView imageView;
		TextView tv;
	}

}
